package com.coins.agent.zb;

import java.util.Observable;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.coins.agent.zb.util.ZBUtils;
import com.coins.common.jobs.JobMessage;
import com.coins.common.utils.BaseObserver;

/**
 * 功能：接收配置数据
 * 
 * @author 任梁荣
 */
public class ZBMarketsOnWorker implements BaseObserver {

	protected static final Logger LOGGER = LoggerFactory.getLogger(ZBMarketsOnWorker.class);

	@Override
	public void update(Observable o, Object arg) {
		Object[] args = (Object[]) arg;
		if (args != null && args.length > 0) {
			if (args[0] instanceof JobMessage) {
				JobMessage msg = (JobMessage) args[0];
				try {
					String result = ZBUtils.markets();
					msg.setResult(result);
					msg.setData(null);
					LOGGER.info("请求URL[" + msg.getEvents() + "]接收到[" + result.length() + "]个字节");
				} catch (Exception e) {
					e.printStackTrace();
					if (LOGGER.isErrorEnabled())
						LOGGER.error(String.format("获取配置数据失败[e = %s]", e.getMessage()));
				}
			}
		}
	}
}
